package com.bluesky.service.lesson025;

import com.bluesky.mapper.lesson025.Lesson025UserMapper;
import com.bluesky.page.PageResult;
import com.bluesky.po.lesson025.Lesson025UserPO;
import com.bluesky.page.PageQuery;
import com.bluesky.dto.lesson025.UserPageQuery;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Lesson025UserService {

    @Autowired
    private Lesson025UserMapper lesson025UserMapper;

    /**
     * 分页获取用户信息
     * @param pageNum 页码
     * @param pageSize 每页大小
     * @return
     */
    public PageResult<Lesson025UserPO> selectPage(int pageNum, int pageSize) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize, true);
        try {
            List<Lesson025UserPO> users = this.lesson025UserMapper.selectPage();
            return PageResult.of(users);
        } finally {
            //清理分页信息
            PageHelper.clearPage();
        }
    }

    /**
     * 分页获取用户信息
     *
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @return
     */
    public PageResult<Lesson025UserPO> selectPageNew(int pageNum, int pageSize) {
        PageQuery pageQuery = PageQuery.of(pageNum, pageSize, true);
        List<Lesson025UserPO> users = this.lesson025UserMapper.selectPageNew(pageQuery);
        return PageResult.of(users);
    }

    /**
     * 分页获取用户信息
     *
     * @param query
     * @return
     */
    public PageResult<Lesson025UserPO> userPage(UserPageQuery query) {
        if (StringUtils.isNotBlank(query.getKeyword())) {
            query.setKeyword("%" + query.getKeyword() + "%");
        }
        List<Lesson025UserPO> users = this.lesson025UserMapper.userPage(query);
        return PageResult.of(users);
    }


}
